package com.training.java.core.homework02;

/**
 * PrintOneThruTen program: In order to avoid printing all variants of loops while, do while, for, for each,
 * I created a menu selection, from where you can select the specific type of loop.

 * @author Shovan
 * 
 */
import java.util.Scanner;

public class PrintOneThruTen {

	public static void main(String[] args) {

		int choice, i;
		int[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

		Scanner input = new Scanner(System.in);

		// Printing menu of choices
		do {
			System.out.println("Method menu:");
			System.out.println("------------");
			System.out.println("1. While");
			System.out.println("2. Do while");
			System.out.println("3. For loop");
			System.out.println("4. For loop over array");
			System.out.println("5. Enhanced for loop (for each)");
			System.out.println("6. Exit");
			System.out.println("");
			System.out.println("Enter choice: ");
			choice = input.nextInt();
		} while (choice < 1 || choice > 6);

		switch (choice) {
		case 1: // while
			i = 1;
			while (i <= 10) {
				System.out.println(i);
				i++;
			}
			break;
		case 2: // do while
			i = 1;
			do {
				System.out.println(i);
				i++;
			} while (i <= 10);
			break;
		case 3: // for loop
			for (i = 1; i <= 10; i++) {
				System.out.println(i);
			}
			break;
		case 4: // for loop over array
			for (i = 0; i < intArray.length; i++) {
				System.out.println(intArray[i]);
			}
			break;
		case 5:
			for (int j : intArray) {
				System.out.println(j);
			}
			break;
		case 6:
			System.out.println("Exiting program");
			break;
		}
		input.close();
	}
}
